﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using Dao.Interface;

namespace Dao
{
    public class LogRepository : Repository<LogMessage>, ILogRepository
    {
        /// <summary>
        /// 获取日志分页集合
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageCount">总页数</param>
        /// <returns></returns>
        public IQueryable<LogMessage> LoadAllLogByPage(int pageIndex, int pageSize, out int pageCount)
        {
            var logList = this.LoadAll();
            int totalCount = logList.Count();//总条数
            //获取总页数
            if (totalCount % pageSize == 0)
            {
                pageCount = totalCount / pageSize;
            }
            else
            {
                pageCount = totalCount / pageSize + 1;
            }
            logList = logList.OrderByDescending(l => l.Date);
            logList = logList.Skip((pageIndex - 1) * pageSize).Take(pageSize);
            return logList;
        }
    }
}
